<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Python中列表和元组的区别 - 社交圈问答社区</title>
    <!-- Bootstrap 5 CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    
    <style>
        /* 基础样式 */
        body {
            font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
            background-color: #f8fafc;
            color: #334155;
            line-height: 1.6;
        }
        
        /* 导航栏样式 */
        .navbar {
            background-color: white;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
            padding: 0.75rem 0;
        }
        
        .logo {
            font-weight: 700;
            font-size: 1.5rem;
            color: #2563eb;
            text-decoration: none;
            display: flex;
            align-items: center;
            gap: 0.5rem;
        }
        
        .logo i {
            font-size: 1.75rem;
        }
        
        .nav-link {
            color: #64748b;
            font-weight: 500;
            margin: 0 0.5rem;
            transition: all 0.2s ease;
            padding: 0.5rem 0.75rem;
        }
        
        .nav-link:hover, .nav-link.active {
            color: #2563eb;
        }
        
        .search-bar {
            max-width: 300px;
            width: 100%;
            position: relative;
        }
        
        .search-bar input {
            padding-left: 2.5rem;
            background-color: #f1f5f9;
            border-color: #e2e8f0;
        }
        
        .search-bar i {
            position: absolute;
            left: 0.75rem;
            top: 50%;
            transform: translateY(-50%);
            color: #94a3b8;
        }
        
        .user-actions {
            display: flex;
            align-items: center;
            gap: 1rem;
        }
        
        .user-avatar {
            width: 38px;
            height: 38px;
            border-radius: 50%;
            object-fit: cover;
            cursor: pointer;
            border: 2px solid transparent;
            transition: border-color 0.2s ease;
        }
        
        .user-avatar:hover {
            border-color: #2563eb;
        }
        
        .create-btn {
            background-color: #2563eb;
            color: white;
            border: none;
            border-radius: 6px;
            padding: 0.5rem 1rem;
            display: flex;
            align-items: center;
            gap: 0.5rem;
            font-weight: 500;
            transition: all 0.2s ease;
        }
        
        .create-btn:hover {
            background-color: #1d4ed8;
            transform: translateY(-2px);
            box-shadow: 0 4px 12px rgba(37, 99, 235, 0.2);
        }
        
        /* 主内容区 */
        .main-container {
            padding: 2rem 0;
        }
        
        /* 路径导航 */
        .breadcrumbs {
            margin-bottom: 1.5rem;
            font-size: 0.9rem;
            color: #64748b;
        }
        
        .breadcrumbs a {
            color: #64748b;
            text-decoration: none;
            transition: color 0.2s ease;
        }
        
        .breadcrumbs a:hover {
            color: #2563eb;
            text-decoration: underline;
        }
        
        .breadcrumbs span {
            margin: 0 0.5rem;
            color: #94a3b8;
        }
        
        /* 问答详情卡片 */
        .qa-card {
            background-color: white;
            border-radius: 10px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
            overflow: hidden;
            margin-bottom: 2rem;
        }
        
        .qa-header {
            padding: 1.5rem;
            border-bottom: 1px solid #f1f5f9;
        }
        
        .qa-status {
            display: inline-flex;
            align-items: center;
            gap: 0.25rem;
            padding: 0.25rem 0.75rem;
            border-radius: 4px;
            font-weight: 500;
            font-size: 0.85rem;
            margin-bottom: 1rem;
        }
        
        .status-answered {
            background-color: #f0fdf4;
            color: #16a34a;
        }
        
        .qa-title {
            font-size: 1.5rem;
            font-weight: 700;
            color: #1e293b;
            margin-bottom: 1rem;
            line-height: 1.4;
        }
        
        .qa-meta {
            display: flex;
            justify-content: space-between;
            align-items: center;
            font-size: 0.9rem;
            color: #64748b;
            flex-wrap: wrap;
            gap: 1rem;
        }
        
        .qa-author {
            display: flex;
            align-items: center;
            gap: 0.75rem;
        }
        
        .author-info {
            display: flex;
            align-items: center;
            gap: 0.5rem;
        }
        
        .author-avatar {
            width: 40px;
            height: 40px;
            border-radius: 50%;
            object-fit: cover;
        }
        
        .author-name {
            font-weight: 500;
            color: #334155;
        }
        
        .author-badge {
            background-color: #dbeafe;
            color: #1d4ed8;
            font-size: 0.75rem;
            padding: 0.15rem 0.5rem;
            border-radius: 4px;
            font-weight: 500;
        }
        
        .qa-time {
            display: flex;
            align-items: center;
            gap: 0.25rem;
        }
        
        .qa-tags {
            display: flex;
            flex-wrap: wrap;
            gap: 0.75rem;
            margin-top: 1rem;
        }
        
        .qa-tag {
            background-color: #f1f5f9;
            color: #64748b;
            font-size: 0.85rem;
            padding: 0.25rem 0.75rem;
            border-radius: 4px;
            transition: all 0.2s ease;
            text-decoration: none;
        }
        
        .qa-tag:hover {
            background-color: #e2e8f0;
            color: #475569;
        }
        
        .qa-content {
            padding: 1.5rem;
            line-height: 1.8;
            color: #334155;
            font-size: 1.05rem;
        }
        
        .qa-content p {
            margin-bottom: 1rem;
        }
        
        .qa-content pre {
            background-color: #f8fafc;
            border-radius: 6px;
            padding: 1rem;
            margin-bottom: 1rem;
            overflow-x: auto;
            font-family: 'Fira Code', monospace;
            font-size: 0.9rem;
        }
        
        .qa-content img {
            max-width: 100%;
            border-radius: 6px;
            margin: 1rem 0;
        }
        
        .qa-actions {
            padding: 1rem 1.5rem;
            border-top: 1px solid #f1f5f9;
            display: flex;
            justify-content: space-between;
            align-items: center;
            flex-wrap: wrap;
            gap: 1rem;
        }
        
        .action-buttons {
            display: flex;
            gap: 1rem;
        }
        
        .action-btn {
            background: none;
            border: none;
            display: flex;
            align-items: center;
            gap: 0.35rem;
            color: #64748b;
            font-weight: 500;
            padding: 0.4rem 0.75rem;
            border-radius: 6px;
            transition: all 0.2s ease;
            cursor: pointer;
        }
        
        .action-btn:hover {
            background-color: #f1f5f9;
            color: #2563eb;
        }
        
        .action-btn.voted {
            color: #2563eb;
        }
        
        .action-btn.bookmarked {
            color: #eab308;
        }
        
        .share-dropdown .dropdown-toggle {
            display: flex;
            align-items: center;
            gap: 0.35rem;
        }
        
        /* 回答区域 */
        .answers-section {
            margin-bottom: 2rem;
        }
        
        .answers-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 1.5rem;
            flex-wrap: wrap;
            gap: 1rem;
        }
        
        .answers-title {
            font-size: 1.35rem;
            font-weight: 600;
            color: #1e293b;
            display: flex;
            align-items: center;
            gap: 0.5rem;
        }
        
        .answers-count {
            background-color: #f1f5f9;
            color: #64748b;
            padding: 0.15rem 0.75rem;
            border-radius: 20px;
            font-size: 0.9rem;
            font-weight: 500;
        }
        
        .answer-btn {
            background-color: #2563eb;
            color: white;
            border: none;
            border-radius: 6px;
            padding: 0.65rem 1.25rem;
            display: flex;
            align-items: center;
            gap: 0.5rem;
            font-weight: 500;
            transition: all 0.2s ease;
        }
        
        .answer-btn:hover {
            background-color: #1d4ed8;
            box-shadow: 0 4px 12px rgba(37, 99, 235, 0.2);
        }
        
        /* 回答项 */
        .answer-item {
            background-color: white;
            border-radius: 10px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
            padding: 1.5rem;
            margin-bottom: 1.5rem;
            transition: transform 0.2s ease, box-shadow 0.2s ease;
        }
        
        .answer-item:hover {
            transform: translateY(-3px);
            box-shadow: 0 8px 16px rgba(0, 0, 0, 0.08);
        }
        
        .answer-accepted {
            display: inline-flex;
            align-items: center;
            gap: 0.35rem;
            background-color: #f0fdf4;
            color: #16a34a;
            padding: 0.25rem 0.75rem;
            border-radius: 4px;
            font-size: 0.9rem;
            font-weight: 500;
            margin-bottom: 1rem;
        }
        
        .answer-content {
            margin-bottom: 1.5rem;
            line-height: 1.8;
        }
        
        .answer-meta {
            display: flex;
            justify-content: space-between;
            align-items: center;
            font-size: 0.9rem;
            color: #64748b;
            padding-top: 1rem;
            border-top: 1px solid #f1f5f9;
            flex-wrap: wrap;
            gap: 1rem;
        }
        
        .answer-author {
            display: flex;
            align-items: center;
            gap: 0.75rem;
        }
        
        .answer-actions {
            display: flex;
            gap: 0.75rem;
        }
        
        /* 评论区域 */
        .comments-section {
            margin-top: 1.5rem;
        }
        
        .comments-header {
            display: flex;
            align-items: center;
            gap: 0.5rem;
            margin-bottom: 1rem;
            cursor: pointer;
            color: #64748b;
            font-weight: 500;
        }
        
        .comments-list {
            padding-left: 1.5rem;
            margin-bottom: 1.5rem;
        }
        
        .comment-item {
            padding: 1rem 0;
            border-bottom: 1px solid #f1f5f9;
        }
        
        .comment-item:last-child {
            border-bottom: none;
        }
        
        .comment-header {
            display: flex;
            justify-content: space-between;
            margin-bottom: 0.5rem;
        }
        
        .comment-author {
            display: flex;
            align-items: center;
            gap: 0.5rem;
            font-weight: 500;
            color: #334155;
        }
        
        .comment-author-avatar {
            width: 32px;
            height: 32px;
            border-radius: 50%;
            object-fit: cover;
        }
        
        .comment-time {
            font-size: 0.85rem;
            color: #94a3b8;
        }
        
        .comment-content {
            margin-bottom: 0.75rem;
            color: #334155;
        }
        
        .comment-actions {
            display: flex;
            gap: 1rem;
            font-size: 0.85rem;
        }
        
        .comment-action {
            color: #64748b;
            text-decoration: none;
            transition: color 0.2s ease;
            display: flex;
            align-items: center;
            gap: 0.25rem;
        }
        
        .comment-action:hover {
            color: #2563eb;
        }
        
        /* 评论输入框 */
        .comment-form {
            margin-top: 1.5rem;
        }
        
        .comment-form textarea {
            width: 100%;
            padding: 1rem;
            border: 1px solid #e2e8f0;
            border-radius: 6px;
            resize: vertical;
            min-height: 100px;
            font-family: inherit;
            transition: all 0.2s ease;
        }
        
        .comment-form textarea:focus {
            outline: none;
            border-color: #2563eb;
            box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
        }
        
        .comment-form-actions {
            display: flex;
            justify-content: flex-end;
            margin-top: 1rem;
            gap: 1rem;
        }
        
        .cancel-btn {
            background-color: #f1f5f9;
            color: #64748b;
            border: none;
            border-radius: 6px;
            padding: 0.65rem 1.25rem;
            font-weight: 500;
            transition: all 0.2s ease;
            cursor: pointer;
        }
        
        .cancel-btn:hover {
            background-color: #e2e8f0;
            color: #475569;
        }
        
        .submit-btn {
            background-color: #2563eb;
            color: white;
            border: none;
            border-radius: 6px;
            padding: 0.65rem 1.25rem;
            font-weight: 500;
            transition: all 0.2s ease;
            cursor: pointer;
        }
        
        .submit-btn:hover {
            background-color: #1d4ed8;
            box-shadow: 0 4px 12px rgba(37, 99, 235, 0.2);
        }
        
        /* 侧边栏 */
        .sidebar {
            display: flex;
            flex-direction: column;
            gap: 1.5rem;
        }
        
        .sidebar-card {
            background-color: white;
            border-radius: 10px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
            padding: 1.5rem;
        }
        
        .sidebar-title {
            font-size: 1.1rem;
            font-weight: 600;
            color: #1e293b;
            margin-bottom: 1rem;
            display: flex;
            align-items: center;
            gap: 0.5rem;
        }
        
        .sidebar-title i {
            color: #2563eb;
        }
        
        .related-questions {
            list-style: none;
            padding: 0;
            margin: 0;
        }
        
        .related-question-item {
            margin-bottom: 1rem;
        }
        
        .related-question-item:last-child {
            margin-bottom: 0;
        }
        
        .related-question-link {
            color: #334155;
            text-decoration: none;
            transition: color 0.2s ease;
            line-height: 1.4;
        }
        
        .related-question-link:hover {
            color: #2563eb;
            text-decoration: underline;
        }
        
        .question-stats {
            display: flex;
            flex-direction: column;
            gap: 0.75rem;
        }
        
        .stat-item {
            display: flex;
            justify-content: space-between;
            padding-bottom: 0.75rem;
            border-bottom: 1px solid #f1f5f9;
        }
        
        .stat-item:last-child {
            border-bottom: none;
            padding-bottom: 0;
        }
        
        .stat-label {
            color: #64748b;
        }
        
        .stat-value {
            font-weight: 600;
            color: #1e293b;
        }
        
        /* 响应式调整 */
        @media (max-width: 992px) {
            .search-bar {
                max-width: 200px;
            }
            
            .sidebar {
                margin-top: 2rem;
            }
        }
        
        @media (max-width: 768px) {
            .navbar-nav {
                margin-top: 1rem;
            }
            
            .search-bar {
                max-width: 100%;
                margin: 1rem 0;
            }
            
            .user-actions {
                margin-top: 1rem;
            }
            
            .qa-title {
                font-size: 1.35rem;
            }
            
            .action-buttons {
                flex-wrap: wrap;
            }
        }
        
        @media (max-width: 576px) {
            .qa-meta {
                flex-direction: column;
                align-items: flex-start;
            }
            
            .answers-header {
                flex-direction: column;
                align-items: flex-start;
            }
            
            .answer-meta {
                flex-direction: column;
                align-items: flex-start;
            }
            
            .comment-header {
                flex-direction: column;
                align-items: flex-start;
                gap: 0.5rem;
            }
        }
    </style>
</head>
<body>
    <!-- 导航栏 -->
    <nav class="navbar navbar-expand-lg">
        <div class="container">
            <a href="#" class="logo">
                <i class="fas fa-comments"></i>
                <span>社交圈</span>
            </a>
            
            <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
                <i class="fas fa-bars"></i>
            </button>
            
            <div class="collapse navbar-collapse" id="navbarNav">
                <ul class="navbar-nav me-auto">
                    <li class="nav-item">
                        <a class="nav-link" href="#"><i class="fas fa-home me-1"></i> 首页</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="#"><i class="fas fa-comments me-1"></i> 投票</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="#"><i class="fas fa-newspaper me-1"></i> 文章</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="#"><i class="fas fa-image me-1"></i> 相册</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="#"><i class="fas fa-briefcase me-1"></i> 招聘</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link active" href="#"><i class="fas fa-question-circle me-1"></i> 问答</a>
                    </li>
                </ul>
                
                <div class="d-flex align-items-center gap-3 flex-wrap">
                    <div class="search-bar">
                        <i class="fas fa-search"></i>
                        <input type="text" class="form-control" placeholder="搜索问答...">
                    </div>
                    
                    <div class="user-actions">
                        <button class="create-btn">
                            <i class="fas fa-plus"></i>
                            <span>提问</span>
                        </button>
                        <img src="https://picsum.photos/id/1005/38/38" alt="用户头像" class="user-avatar">
                    </div>
                </div>
            </div>
        </div>
    </nav>
    
    <!-- 主内容区 -->
    <div class="main-container">
        <div class="container">
            <!-- 路径导航 -->
            <div class="breadcrumbs">
                <a href="#">首页</a>
                <span>›</span>
                <a href="#">问答</a>
                <span>›</span>
                <a href="#">技术</a>
                <span>›</span>
                <span>Python中列表和元组的区别</span>
            </div>
            
            <div class="row">
                <!-- 主要内容区 -->
                <div class="col-lg-8">
                    <!-- 问答详情卡片 -->
                    <div class="qa-card">
                        <div class="qa-header">
                            <span class="qa-status status-answered">
                                <i class="fas fa-check"></i>
                                已解决
                            </span>
                            <h1 class="qa-title">Python中列表和元组的主要区别是什么？在实际开发中应该如何选择使用？</h1>
                            
                            <div class="qa-meta">
                                <div class="qa-author">
                                    <div class="author-info">
                                        <img src="https://picsum.photos/id/1012/40/40" alt="提问者头像" class="author-avatar">
                                        <div>
                                            <span class="author-name">编程初学者</span>
                                            <span class="author-badge">新手</span>
                                        </div>
                                    </div>
                                    <span class="qa-time">
                                        <i class="far fa-clock"></i>
                                        提问于 2023-07-15 09:30
                                    </span>
                                </div>
                            </div>
                            
                            <div class="qa-tags">
                                <a href="#" class="qa-tag">Python</a>
                                <a href="#" class="qa-tag">列表</a>
                                <a href="#" class="qa-tag">元组</a>
                                <a href="#" class="qa-tag">数据结构</a>
                            </div>
                        </div>
                        
                        <div class="qa-content">
                            <p>我刚开始学习Python，对于列表（list）和元组（tuple）这两种数据结构感到有些困惑。它们看起来很相似，都可以存储多个元素，但我知道它们之间一定有区别。</p>
                            
                            <p>我想了解：</p>
                            <ol>
                                <li>列表和元组的主要区别是什么？</li>
                                <li>在实际开发中，应该根据什么标准来选择使用列表还是元组？</li>
                                <li>有没有一些常见的使用场景示例可以帮助我理解？</li>
                            </ol>
                            
                            <p>希望各位大神能够解答我的疑问，非常感谢！</p>
                        </div>
                        
                        <div class="qa-actions">
                            <div class="action-buttons">
                                <button class="action-btn voted">
                                    <i class="fas fa-thumbs-up"></i>
                                    <span>赞同 (42)</span>
                                </button>
                                <button class="action-btn">
                                    <i class="fas fa-thumbs-down"></i>
                                    <span>反对</span>
                                </button>
                                <button class="action-btn bookmarked">
                                    <i class="fas fa-bookmark"></i>
                                    <span>已收藏</span>
                                </button>
                                <button class="action-btn">
                                    <i class="fas fa-flag"></i>
                                    <span>举报</span>
                                </button>
                            </div>
                            
                            <div class="share-dropdown btn-group">
                                <button type="button" class="action-btn dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
                                    <i class="fas fa-share-alt"></i>
                                    <span>分享</span>
                                </button>
                                <ul class="dropdown-menu">
                                    <li><a class="dropdown-item" href="#"><i class="fab fa-weixin me-2"></i>微信</a></li>
                                    <li><a class="dropdown-item" href="#"><i class="fab fa-weibo me-2"></i>微博</a></li>
                                    <li><a class="dropdown-item" href="#"><i class="fab fa-qq me-2"></i>QQ</a></li>
                                    <li><a class="dropdown-item" href="#"><i class="fas fa-link me-2"></i>复制链接</a></li>
                                </ul>
                            </div>
                        </div>
                    </div>
                    
                    <!-- 回答区域 -->
                    <div class="answers-section">
                        <div class="answers-header">
                            <h2 class="answers-title">
                                回答
                                <span class="answers-count">8 个回答</span>
                            </h2>
                            <button class="answer-btn">
                                <i class="fas fa-reply"></i>
                                <span>写下你的回答</span>
                            </button>
                        </div>
                        
                        <!-- 回答1（被采纳的回答） -->
                        <div class="answer-item">
                            <div class="answer-accepted">
                                <i class="fas fa-check-circle"></i>
                                <span>被采纳的回答</span>
                            </div>
                            
                            <div class="answer-content">
                                <p>Python中的列表（list）和元组（tuple）确实有很多相似之处，但它们的核心区别在于<em>可变性</em>，这也决定了它们的不同使用场景。</p>
                                
                                <h4>1. 主要区别</h4>
                                <ul>
                                    <li><strong>可变性</strong>：列表是可变的（mutable），元组是不可变的（immutable）。这意味着列表创建后可以修改其元素，而元组创建后不能修改其元素。</li>
                                    <li><strong>语法表示</strong>：列表使用方括号 <code>[]</code>，元组使用圆括号 <code>()</code>。</li>
                                    <li><strong>性能</strong>：元组的访问速度通常比列表快，因为其不可变性使得内存分配更高效。</li>
                                    <li><strong>适用场景</strong>：列表适用于需要动态修改的数据集合，元组适用于存储不应被修改的数据。</li>
                                </ul>
                                
                                <h4>2. 代码示例</h4>
                                <pre>
# 列表示例 - 可修改
my_list = [1, 2, 3]
my_list[0] = 100  # 合法操作
my_list.append(4)  # 合法操作
print(my_list)  # 输出: [100, 2, 3, 4]

# 元组示例 - 不可修改
my_tuple = (1, 2, 3)
my_tuple[0] = 100  # 会抛出TypeError错误
my_tuple.append(4)  # 会抛出AttributeError错误
                                </pre>
                                
                                <h4>3. 如何选择使用</h4>
                                <p>在实际开发中，可以根据以下原则选择：</p>
                                <ul>
                                    <li>如果需要存储的数据在程序运行过程中可能发生变化（添加、删除、修改元素），使用列表。</li>
                                    <li>如果需要存储的数据是固定不变的，或者希望数据不被意外修改，使用元组。</li>
                                    <li>元组可以作为字典的键，而列表不能，因为字典键需要是不可变的。</li>
                                    <li>当函数需要返回多个值时，通常使用元组。</li>
                                </ul>
                                
                                <h4>4. 常见使用场景</h4>
                                <ul>
                                    <li>列表：存储用户输入的动态数据、需要排序或过滤的数据集合、实现栈或队列等数据结构。</li>
                                    <li>元组：存储坐标（x, y）、日期（年, 月, 日）、数据库记录等不应被修改的数据；函数返回多个值；作为字典的键。</li>
                                </ul>
                            </div>
                            
                            <div class="answer-meta">
                                <div class="answer-author">
                                    <div class="author-info">
                                        <img src="https://picsum.photos/id/1025/40/40" alt="回答者头像" class="author-avatar">
                                        <div>
                                            <span class="author-name">Python工程师</span>
                                            <span class="author-badge">专家</span>
                                        </div>
                                    </div>
                                    <span class="qa-time">
                                        <i class="far fa-clock"></i>
                                        回答于 2023-07-15 10:15
                                    </span>
                                </div>
                                
                                <div class="answer-actions">
                                    <button class="action-btn voted">
                                        <i class="fas fa-thumbs-up"></i>
                                        <span>68</span>
                                    </button>
                                    <button class="action-btn">
                                        <i class="fas fa-thumbs-down"></i>
                                        <span>2</span>
                                    </button>
                                    <button class="action-btn">
                                        <i class="fas fa-comment"></i>
                                        <span>评论 (5)</span>
                                    </button>
                                </div>
                            </div>
                            
                            <!-- 评论区域 -->
                            <div class="comments-section">
                                <div class="comments-list">
                                    <!-- 评论1 -->
                                    <div class="comment-item">
                                        <div class="comment-header">
                                            <div class="comment-author">
                                                <img src="https://picsum.photos/id/1074/32/32" alt="评论者头像" class="comment-author-avatar">
                                                <span>数据分析师</span>
                                            </div>
                                            <span class="comment-time">2023-07-15 11:03</span>
                                        </div>
                                        <div class="comment-content">
                                            非常全面的解释！补充一点：当你需要在循环中频繁修改数据时，列表通常是更好的选择，因为元组的不可变性意味着每次"修改"实际上是创建一个新的元组，效率较低。
                                        </div>
                                        <div class="comment-actions">
                                            <a href="#" class="comment-action">
                                                <i class="fas fa-thumbs-up"></i>
                                                <span>12</span>
                                            </a>
                                            <a href="#" class="comment-action">回复</a>
                                        </div>
                                        
                                        <!-- 评论的回复 -->
                                        <div class="comments-list" style="margin-top: 1rem;">
                                            <div class="comment-item">
                                                <div class="comment-header">
                                                    <div class="comment-author">
                                                        <img src="https://picsum.photos/id/1025/32/32" alt="回复者头像" class="comment-author-avatar">
                                                        <span>Python工程师</span>
                                                    </div>
                                                    <span class="comment-time">2023-07-15 11:20</span>
                                                </div>
                                                <div class="comment-content">
                                                    是的，你说得对。对于需要频繁修改的场景，列表的效率确实更高。
                                                </div>
                                                <div class="comment-actions">
                                                    <a href="#" class="comment-action">
                                                        <i class="fas fa-thumbs-up"></i>
                                                        <span>5</span>
                                                    </a>
                                                    <a href="#" class="comment-action">回复</a>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    
                                    <!-- 更多评论 -->
                                    <div class="comment-item">
                                        <div class="comment-header">
                                            <div class="comment-author">
                                                <img src="https://picsum.photos/id/1066/32/32" alt="评论者头像" class="comment-author-avatar">
                                                <span>全栈开发者</span>
                                            </div>
                                            <span class="comment-time">2023-07-15 14:45</span>
                                        </div>
                                        <div class="comment-content">
                                            还想请教一下，元组的不可变性在多线程环境下有什么优势吗？
                                        </div>
                                        <div class="comment-actions">
                                            <a href="#" class="comment-action">
                                                <i class="fas fa-thumbs-up"></i>
                                                <span>8</span>
                                            </a>
                                            <a href="#" class="comment-action">回复</a>
                                        </div>
                                    </div>
                                </div>
                                
                                <!-- 评论输入框 -->
                                <div class="comment-form">
                                    <textarea placeholder="添加评论..."></textarea>
                                    <div class="comment-form-actions">
                                        <button class="cancel-btn">取消</button>
                                        <button class="submit-btn">发表评论</button>
                                    </div>
                                </div>
                            </div>
                        </div>
                        
                        <!-- 回答2 -->
                        <div class="answer-item">
                            <div class="answer-content">
                                <p>简单来说，记住一句话：<strong>列表是动态的，元组是静态的</strong>。</p>
                                
                                <p>在实际编程中，我通常遵循这样的原则：</p>
                                <ul>
                                    <li>当我需要一个容器来存储一系列相同类型的数据，并且可能需要添加或删除元素时，我使用列表。</li>
                                    <li>当我需要存储一组相关但不同类型的数据，并且不希望它们被修改时，我使用元组。</li>
                                </ul>
                                
                                <p>例如，存储一个用户的兴趣爱好列表，我会用列表，因为用户可能会添加或删除兴趣爱好：</p>
                                <pre>
hobbies = ["reading", "hiking", "coding"]
                                </pre>
                                
                                <p>而存储一个用户的个人信息，我会用元组，因为这些信息相对固定：</p>
                                <pre>
person = ("John Doe", 30, "male", "john@example.com")
                                </pre>
                            </div>
                            
                            <div class="answer-meta">
                                <div class="answer-author">
                                    <div class="author-info">
                                        <img src="https://picsum.photos/id/1074/40/40" alt="回答者头像" class="author-avatar">
                                        <div>
                                            <span class="author-name">数据分析师</span>
                                            <span class="author-badge">高级</span>
                                        </div>
                                    </div>
                                    <span class="qa-time">
                                        <i class="far fa-clock"></i>
                                        回答于 2023-07-15 10:30
                                    </span>
                                </div>
                                
                                <div class="answer-actions">
                                    <button class="action-btn voted">
                                        <i class="fas fa-thumbs-up"></i>
                                        <span>24</span>
                                    </button>
                                    <button class="action-btn">
                                        <i class="fas fa-thumbs-down"></i>
                                        <span>0</span>
                                    </button>
                                    <button class="action-btn">
                                        <i class="fas fa-comment"></i>
                                        <span>评论 (2)</span>
                                    </button>
                                </div>
                            </div>
                            
                            <!-- 评论区域 -->
                            <div class="comments-section">
                                <div class="comments-header">
                                    <i class="fas fa-comments"></i>
                                    <span>查看2条评论</span>
                                </div>
                                
                                <!-- 评论输入框 -->
                                <div class="comment-form">
                                    <textarea placeholder="添加评论..."></textarea>
                                    <div class="comment-form-actions">
                                        <button class="cancel-btn">取消</button>
                                        <button class="submit-btn">发表评论</button>
                                    </div>
                                </div>
                            </div>
                        </div>
                        
                        <!-- 回答3（折叠状态） -->
                        <div class="answer-item">
                            <div class="answer-content">
                                <p>从内存占用的角度来看，元组通常比列表更节省内存空间。这是因为元组的大小是固定的，而列表需要额外的空间来支持动态增长。</p>
                                
                                <p>可以通过以下代码验证：</p>
                                <pre>
import sys

list_example = [1, 2, 3, 4, 5]
tuple_example = (1, 2, 3, 4, 5)

print(sys.getsizeof(list_example))  # 输出列表的内存大小
print(sys.getsizeof(tuple_example))  # 输出元组的内存大小
                                </pre>
                                
                                <p>在大多数情况下，这种差异可能微不足道，但当处理大量数据时，选择元组可以帮助节省内存。</p>
                            </div>
                            
                            <div class="answer-meta">
                                <div class="answer-author">
                                    <div class="author-info">
                                        <img src="https://picsum.photos/id/1066/40/40" alt="回答者头像" class="author-avatar">
                                        <div>
                                            <span class="author-name">全栈开发者</span>
                                            <span class="author-badge">中级</span>
                                        </div>
                                    </div>
                                    <span class="qa-time">
                                        <i class="far fa-clock"></i>
                                        回答于 2023-07-15 11:45
                                    </span>
                                </div>
                                
                                <div class="answer-actions">
                                    <button class="action-btn voted">
                                        <i class="fas fa-thumbs-up"></i>
                                        <span>15</span>
                                    </button>
                                    <button class="action-btn">
                                        <i class="fas fa-thumbs-down"></i>
                                        <span>1</span>
                                    </button>
                                    <button class="action-btn">
                                        <i class="fas fa-comment"></i>
                                        <span>评论 (0)</span>
                                    </button>
                                </div>
                            </div>
                            
                            <!-- 评论区域 -->
                            <div class="comments-section">
                                <div class="comment-form">
                                    <textarea placeholder="添加评论..."></textarea>
                                    <div class="comment-form-actions">
                                        <button class="cancel-btn">取消</button>
                                        <button class="submit-btn">发表评论</button>
                                    </div>
                                </div>
                            </div>
                        </div>
                        
                        <!-- 加载更多回答按钮 -->
                        <div style="text-align: center; margin-top: 1rem;">
                            <button class="btn btn-outline-primary" style="padding: 0.65rem 2rem;">
                                查看更多回答
                            </button>
                        </div>
                    </div>
                </div>
                
                <!-- 侧边栏 -->
                <div class="col-lg-4">
                    <div class="sidebar">
                        <!-- 问题统计 -->
                        <div class="sidebar-card">
                            <h3 class="sidebar-title">
                                <i class="fas fa-chart-bar"></i>
                                问题统计
                            </h3>
                            <div class="question-stats">
                                <div class="stat-item">
                                    <span class="stat-label">浏览量</span>
                                    <span class="stat-value">1,248</span>
                                </div>
                                <div class="stat-item">
                                    <span class="stat-label">回答数</span>
                                    <span class="stat-value">8</span>
                                </div>
                                <div class="stat-item">
                                    <span class="stat-label">最后活动</span>
                                    <span class="stat-value">今天 09:23</span>
                                </div>
                                <div class="stat-item">
                                    <span class="stat-label">提问时间</span>
                                    <span class="stat-value">2023-07-15</span>
                                </div>
                            </div>
                        </div>
                        
                        <!-- 相关问题 -->
                        <div class="sidebar-card">
                            <h3 class="sidebar-title">
                                <i class="fas fa-question-circle"></i>
                                相关问题
                            </h3>
                            <ul class="related-questions">
                                <li class="related-question-item">
                                    <a href="#" class="related-question-link">Python中字典和集合有什么区别？各自适用于什么场景？</a>
                                </li>
                                <li class="related-question-item">
                                    <a href="#" class="related-question-link">如何在Python中高效地遍历列表和元组？</a>
                                </li>
                                <li class="related-question-item">
                                    <a href="#" class="related-question-link">Python中的列表推导式和生成器表达式有什么区别？</a>
                                </li>
                                <li class="related-question-item">
                                    <a href="#" class="related-question-link">如何将列表转换为元组，反之亦然？转换时有什么注意事项？</a>
                                </li>
                                <li class="related-question-item">
                                    <a href="#" class="related-question-link">Python中处理大型列表时有哪些性能优化技巧？</a>
                                </li>
                            </ul>
                        </div>
                        
                        <!-- 热门标签 -->
                        <div class="sidebar-card">
                            <h3 class="sidebar-title">
                                <i class="fas fa-tags"></i>
                                热门标签
                            </h3>
                            <div class="tag-filter">
                                <div class="tag-item">Python</div>
                                <div class="tag-item">Java</div>
                                <div class="tag-item">前端开发</div>
                                <div class="tag-item">人工智能</div>
                                <div class="tag-item">机器学习</div>
                                <div class="tag-item">数据结构</div>
                                <div class="tag-item">算法</div>
                                <div class="tag-item">数据库</div>
                                <div class="tag-item">Web开发</div>
                                <div class="tag-item">Python基础</div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    
    <!-- Bootstrap 5 JS Bundle with Popper -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
    
    <script>
        // 评论区域展开/折叠功能
        const commentsHeaders = document.querySelectorAll('.comments-header');
        commentsHeaders.forEach(header => {
            header.addEventListener('click', function() {
                const commentsList = this.nextElementSibling;
                if (commentsList && commentsList.classList.contains('comments-list')) {
                    commentsList.style.display = commentsList.style.display === 'none' ? 'block' : 'none';
                    
                    // 切换图标
                    const icon = this.querySelector('i');
                    if (commentsList.style.display === 'none') {
                        icon.classList.remove('fa-chevron-up');
                        icon.classList.add('fa-chevron-down');
                    } else {
                        icon.classList.remove('fa-chevron-down');
                        icon.classList.add('fa-chevron-up');
                    }
                }
            });
        });
        
        // 点赞功能
        const likeButtons = document.querySelectorAll('.action-btn:not(.share-dropdown) .fa-thumbs-up');
        likeButtons.forEach(button => {
            button.parentElement.addEventListener('click', function() {
                this.classList.toggle('voted');
                
                // 更新点赞数
                const countSpan = this.querySelector('span');
                if (countSpan) {
                    let countText = countSpan.textContent;
                    let count = parseInt(countText.match(/\d+/)[0]);
                    
                    if (this.classList.contains('voted')) {
                        count += 1;
                    } else {
                        count -= 1;
                    }
                    
                    // 更新显示的文本
                    if (countText.includes('赞同')) {
                        countSpan.textContent = `赞同 (${count})`;
                    } else {
                        countSpan.textContent = count.toString();
                    }
                }
            });
        });
        
        // 收藏功能
        const bookmarkButtons = document.querySelectorAll('.action-btn .fa-bookmark');
        bookmarkButtons.forEach(button => {
            button.parentElement.addEventListener('click', function() {
                this.classList.toggle('bookmarked');
                
                // 更新文本
                const textSpan = this.querySelector('span');
                if (textSpan) {
                    textSpan.textContent = this.classList.contains('bookmarked') ? '已收藏' : '收藏';
                }
            });
        });
        
        // 反对功能
        const dislikeButtons = document.querySelectorAll('.action-btn .fa-thumbs-down');
        dislikeButtons.forEach(button => {
            button.parentElement.addEventListener('click', function() {
                this.classList.toggle('voted');
                
                // 更新反对数
                const countSpan = this.querySelector('span');
                if (countSpan) {
                    let countText = countSpan.textContent;
                    let count = parseInt(countText.match(/\d+/)[0] || 0);
                    
                    if (this.classList.contains('voted')) {
                        count += 1;
                    } else {
                        count -= 1;
                    }
                    
                    countSpan.textContent = count.toString();
                }
            });
        });
        
        // 评论点赞功能
        const commentLikeButtons = document.querySelectorAll('.comment-action .fa-thumbs-up');
        commentLikeButtons.forEach(button => {
            button.parentElement.addEventListener('click', function(e) {
                e.preventDefault();
                
                const countSpan = this.querySelector('span');
                if (countSpan) {
                    let count = parseInt(countSpan.textContent);
                    count += 1;
                    countSpan.textContent = count.toString();
                }
            });
        });
    </script>
</body>
</html>
    
